package com.jblv.frame.common.fastdfs.fdfs;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author happyonion.yangtao
 * @version 1.0
 * @title ByteToInputStream
 * @projectName jblv-frame
 * @packageName com.jblv.common.fastdfs.fdfs
 * @description ByteToInputStream
 * @date Create at 2020/5/7 11:05
 * @since jdk1.8
 */


public class ByteToInputStream {
    public ByteToInputStream() {
    }

    public static final InputStream byte2Input(byte[] buf) {
        return new ByteArrayInputStream(buf);
    }

    public static final byte[] input2byte(InputStream inStream) throws IOException {
        ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
        byte[] buff = new byte[100];
        boolean var3 = false;

        int rc;
        while((rc = inStream.read(buff, 0, 100)) > 0) {
            swapStream.write(buff, 0, rc);
        }

        byte[] in2b = swapStream.toByteArray();
        inStream.close();
        swapStream.close();
        return in2b;
    }
}
